
#include "member_BShader.h"

using namespace BWE;

member_BShader::member_BShader(BShader* boss)
{
	shader = boss;
	type = BShader::Type_None;
	object = 0;
	dirty = false;
}
member_BShader::~member_BShader()
{
	if (object)
	{
		//BOpenGL::release
	}
}

bool member_BShader::compile()
{
	if (text.empty())
		return false;
	if (dirty)
	{
		if (!object)
		{
			if (type == BShader::Type_Vertex)
				object = glCreateShader(GL_VERTEX_SHADER);
			if (type == BShader::Type_Fragment)
				object = glCreateShader(GL_FRAGMENT_SHADER);
		}
		if (object)
		{
			const char* cstr = text.cstr();
			glShaderSource(object, 1, &cstr, 0);
			if (glGetError() != GL_NO_ERROR)
				return false;
			glCompileShader(object);
			if (glGetError() != GL_NO_ERROR)
				return false;
		}
		dirty = false;
	}
	if (object)
		return true;
	return false;
}
